package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.pojo.RepairPersonnel;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.common.pojo.RepairWorkOrder;
import com.groupseven.happycampus.common.vo.TypeWorkBarVo;
import com.groupseven.happycampus.common.vo.WorkOrderPieVo;
import com.groupseven.happycampus.mapper.RepairMapper;
import com.groupseven.happycampus.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("repairService")
public class RepairServiceImpl implements RepairService {

    @Autowired
    private RepairMapper repairMapper;

    @Override
    public LayuiPageVo<RepairPersonnel> repairPersonnelPageDate(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<RepairPersonnel> personnels = repairMapper.repairPersonnelPageDate(params);
        // mybatis 的 分页数据结构
        PageInfo<RepairPersonnel> personnelPageInfo = new PageInfo<>(personnels);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<RepairPersonnel> personnelLayuiPageVo = new LayuiPageVo<>();
        personnelLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        personnelLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        personnelLayuiPageVo.setCount(personnelPageInfo.getTotal()); // 总记录数
        personnelLayuiPageVo.setData(personnelPageInfo.getList());  // 分页的列表数据
        return personnelLayuiPageVo;
    }

    @Override
    public int addPersonnel(RepairPersonnel personnel) {
        return repairMapper.addPersonnel(personnel);
    }

    @Override
    public int updatePersonnel(RepairPersonnel personnel) {
        return repairMapper.updatePersonnel(personnel);
    }

    @Override
    public int deletePersonnel(Integer id) {
        return repairMapper.deletePersonnel(id);
    }

    @Override
    public int deletesPersonnel(String ids) {
        String[] arrId = ids.split(",");
        return repairMapper.deletesPersonnel(arrId);
    }

    @Override
    public List<TypeWorkBarVo> typeWorkBarData() {
        return repairMapper.typeWorkBarData();
    }

    @Override
    public LayuiPageVo<RepairWorkOrder> workOrderPageDate(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<RepairWorkOrder> workOrders = repairMapper.workOrderPageDate(params);
        // mybatis 的 分页数据结构
        PageInfo<RepairWorkOrder> workOrderPageInfo = new PageInfo<>(workOrders);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<RepairWorkOrder> workOrderLayuiPageVo = new LayuiPageVo<>();
        workOrderLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        workOrderLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        workOrderLayuiPageVo.setCount(workOrderPageInfo.getTotal()); // 总记录数
        workOrderLayuiPageVo.setData(workOrderPageInfo.getList());  // 分页的列表数据
        return workOrderLayuiPageVo;
    }

    @Override
    public int addWorkOrder(RepairWorkOrder workOrder) {
        return repairMapper.addWorkOrder(workOrder);
    }

    @Override
    public int updateWorkOrder(RepairWorkOrder workOrder) {
        return repairMapper.updateWorkOrder(workOrder);
    }

    @Override
    public int deleteWorkOrder(Integer id) {
        return repairMapper.deleteWorkOrder(id);
    }

    @Override
    public int deletesWorkOrder(String ids) {
        String[] arrId = ids.split(",");
        return repairMapper.deletesWorkOrder(arrId);
    }

    @Override
    public List<WorkOrderPieVo> workOrderPieData() {
        return repairMapper.workOrderPieData();
    }

    @Override
    public int giveEndTime(RepairWorkOrder workOrder) {
        return repairMapper.giveEndTime(workOrder);
    }

    @Override
    public List<TypeWorkBarVo> workOrderBarData() {
        return repairMapper.workOrderBarData();
    }

    @Override
    public LayuiPageVo<RepairPersonnel> appointPageDate(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<RepairPersonnel> personnels = repairMapper.appointPageDate(params);
        // mybatis 的 分页数据结构
        PageInfo<RepairPersonnel> personnelPageInfo = new PageInfo<>(personnels);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<RepairPersonnel> personnelLayuiPageVo = new LayuiPageVo<>();
        personnelLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        personnelLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        personnelLayuiPageVo.setCount(personnelPageInfo.getTotal()); // 总记录数
        personnelLayuiPageVo.setData(personnelPageInfo.getList());  // 分页的列表数据
        return personnelLayuiPageVo;
    }

    @Override
    public int giveWork(RepairWorkOrder workOrder) {
        return repairMapper.giveWork(workOrder);
    }


}
